package com.zdth.wxpush.cron;

import com.zdth.wxpush.common.ConName;
import com.zdth.wxpush.common.People;
import com.zdth.wxpush.util.WxPushUtil;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author Z-7
 * @Date 2022/8/29
 */
@Slf4j
@Component
@EnableScheduling
public class AutoSend {

    @Autowired
    private WxPushUtil wxPushUtil;

    @Scheduled(cron = "0 0 7 * * ?")
    public void sendToday() {
        try {
            wxPushUtil.sendMessage(People.ME,7);
            wxPushUtil.sendMessage(People.GX,7);
            wxPushUtil.sendMessage(People.SG,7);
            wxPushUtil.sendToGaoLing(People.GL,7);
            wxPushUtil.sendToGaoLing(People.QJ,7);
            wxPushUtil.sendMessage(People.XBL,7);
            //
            wxPushUtil.sendOther(People.WXGE,7);

        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 天气预报
     */
    @Scheduled(cron = "0 0 23 * * ?")
    public void sendYuBao() {
        try {

            wxPushUtil.sendMessage(People.ME,8);
            wxPushUtil.sendMessage(People.GX,8);
            wxPushUtil.sendMessage(People.SG,8);
            wxPushUtil.sendToGaoLing(People.GL,8);
            wxPushUtil.sendToGaoLing(People.QJ,8);
            wxPushUtil.sendMessage(People.XBL,8);

            //
            wxPushUtil.sendOther(People.WXGE,8);
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 热搜
     */
    @Scheduled(cron = "0 0 12,18 * * ?")
    public void sendTopSearch() {
        try {
            wxPushUtil.sendTopSearch();
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 摸鱼日记
     */
    @Scheduled(cron = "0 0 9 * * ?")
    public void sendMoYu() {
        try {
            // 我
            wxPushUtil.sendMoYuPic(People.ME);
            // 国旭
            wxPushUtil.sendMoYuPic(People.GX);
            // 门三
            wxPushUtil.sendMoYuPic(People.SG);
            // 高玲
            wxPushUtil.sendMoYuPic(People.GL);
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 舔狗日记
     */
    @Scheduled(cron = "0 0 10,22 * * ?")
    public void sendDog() {
        try {
            // 我
            wxPushUtil.sendDog(People.ME);
            // 国旭
            wxPushUtil.sendDog(People.GX);
            // 门三
            wxPushUtil.sendDog(People.SG);
            // 高玲
            wxPushUtil.sendDog(People.GL);
            // 苏
            wxPushUtil.sendDog(People.SYL);
            // 小碧龙
            wxPushUtil.sendDog(People.XBL);
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 舔狗日记
     */
    //@Scheduled(cron = "0 0/2 * * * ?")
    public void sendDogTop() {
        try {
            // 悄漫雾
            wxPushUtil.sendDog(People.QMW);
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 星座推送
     */
    @Scheduled(cron = "0 30 7 * * ?")
    public void sendXingZuo() {
        try {
            // 我
            wxPushUtil.sendXingZuo(People.ME, ConName.LEO);
            // 门三
            wxPushUtil.sendXingZuo(People.SG,ConName.SAGITTARIUS);
            // 苏
            wxPushUtil.sendXingZuo(People.SYL,ConName.CANCER);
            //
            wxPushUtil.sendXingZuo(People.WXGE,ConName.PISCES);
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 因为买家秀有时候会图片不存在 所以重试一次 这里没做优化
     */
    @Scheduled(cron = "0 0 0/1 * * ?")
    public void sendNv() {
        try {
            log.info("开始发送大美妞=========");
            wxPushUtil.sendPic("odJas5xlQTeIRk3ZqDqPKfeVibyA");
        } catch (WxErrorException e) {
            log.info("国旭 --- > 重试");
            try {
                wxPushUtil.sendPic("odJas5xlQTeIRk3ZqDqPKfeVibyA");
            } catch (WxErrorException ex) {
                throw new RuntimeException(ex);
            }
            throw new RuntimeException(e);
        }

        try {
            wxPushUtil.sendPic("odJas5_9M6pEpAWw4TeTP-xaOnWg");
        } catch (WxErrorException e) {
            try {
                log.info("我 --- > 重试");
                wxPushUtil.sendPic("odJas5_9M6pEpAWw4TeTP-xaOnWg");
            } catch (WxErrorException ex) {
                throw new RuntimeException(ex);
            }
            throw new RuntimeException(e);
        }
    }
}
